// ignore_for_file: constant_identifier_names

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_page/community_business/post_detail_page/post_detail_page.dart';
import 'package:tiktokadult/hj_page/main_page/main_page_binding.dart';
import 'package:tiktokadult/hj_page/main_page/main_page_view.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/bing_phone_page.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/mine_find_account_page.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/mine_password_page.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/mine_scan_login_page.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/mine_setting_page.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/mine_setting_profile_page.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/setting_avatar_page.dart';
import 'package:tiktokadult/hj_page/mine_business/more_question/mine_feedback_page.dart';
import 'package:tiktokadult/hj_page/pre_sale/pre_sale_page.dart';
import 'package:tiktokadult/hj_page/user_center_page/user_center_page.dart';
import 'package:tiktokadult/tools_base/global_store/store.dart';

import '../hj_page/cartoon_business/novel_detail_page.dart';
import '../hj_page/community_business/community_tag_page/community_tag_page.dart';
import '../hj_page/community_business/publish_page/chose_tag_page.dart';
import '../hj_page/community_business/publish_page/publish_page.dart';
import '../hj_page/community_business/publish_page/publish_rule_page.dart';
import '../hj_page/mine_business/message/message_center_page.dart';
import '../hj_page/mine_business/mine_setting/qr_scan_page.dart';
import '../hj_page/splash/splash_page.dart';

class AppRoutes {
  static final routePages = [
    GetPage(name: SplashPage.routeName, page: () => const SplashPage(), middlewares: [SplashPasswordMiddleware()]),
    GetPage(name: MainPage.routeName, page: () => MainPage(), binding: MainPageBinding()),

    GetPage(name: MineSettingPage.routeName, page: () => MineSettingPage()),

    GetPage(name: UserCenterPage.routeName, page: () => UserCenterPage()),

    GetPage(name: QrScanPage.routeName, page: () => QrScanPage()),
    GetPage(name: PreSalePage.routeName, page: () => PreSalePage()),
    GetPage(name: MineFeedbackPage.routeName, page: () => MineFeedbackPage()),
    //

    // 帖子详情
    GetPage(name: PostDetailPage.routeName, page: () => PostDetailPage()),
    // 标签详情
    GetPage(name: CommunityTagDetailPage.routeName, page: () => CommunityTagDetailPage()),
    //
    // GetPage(name: MoreRecommendUpPage.routeName, page: () => MoreRecommendUpPage()),

    /// 发布
    GetPage(name: PublishPage.routeName, page: () => PublishPage()),

    ///
    GetPage(name: PublishRulePage.routeName, page: () => PublishRulePage()),

    ///
    GetPage(
        name: ChoseTopicPage.routeName,
        page: () {
          final arg = Get.arguments;
          final selectTags = arg['select'].value;
          final entry = arg['tag'];
          return ChoseTopicPage(
            selectTags: selectTags,
            entry: entry,
          );
        }),

    ///我的消息
    GetPage(name: MessageCenterPage.routeName, page: () => MessageCenterPage()),

    GetPage(name: NovelDetailPage.routeName, page: () => NovelDetailPage()),

    GetPage(
        name: SettingProfilePage.routeName,
        page: () {
          return SettingProfilePage(Get.arguments ?? SettingProfileType.nickName);
        }),
    GetPage(name: BindPhonePage.routeName, page: () => BindPhonePage()),
    GetPage(name: SettingAvatarPage.routeName, page: () => SettingAvatarPage()),
    GetPage(name: MineFindAccountPage.routeName, page: () => MineFindAccountPage()), //账号凭证
    GetPage(name: MineScanLoginPage.routeName, page: () => MineScanLoginPage()),
    GetPage(name: MinePasswordPage.routeNmae, page: () => MinePasswordPage()), //设置锁屏密码
  ];
}

class SplashPasswordMiddleware extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    if (globalStore.password.isEmpty) return super.redirect(route);
    if (globalStore.isChecked) return super.redirect(route);
    return RouteSettings(name: MinePasswordPage.routeNmae, arguments: MinePasswordType.check);
  }
}
